/*
** alloc.h for malloc in /home/morel_t//Rendu/systemUnix
**
** Made by thomas morel
** Login   <morel_t@epitech.net>
**
** Started on  Mon Jan 30 09:46:15 2012 thomas morel
** Last update Fri Feb  3 12:04:02 2012 florian jousseau
*/

#ifndef ALLOC_H_
# define ALLOC_H_

#include <stdlib.h>
#include <sys/types.h>

#define	align4(size)	(((((size) - 1) >> 2) << 2) + 4)

typedef struct s_alloc	*t_alloc;

struct	s_alloc
{
  size_t	size;
  int		free;
  t_alloc	next;
  t_alloc	prev;
  void		*data;
  char		delim[1];
};

#define	BLOCK_SIZE	(sizeof(struct s_alloc) - 8)

/* System Call */
int	brk(void *addr);
void	*sbrk(size_t increment);

/* Alloc Functions */
void	*malloc(size_t size);
void	*realloc(void *ptr, size_t size);
void	*calloc(size_t number, size_t size);
void	free(void *ptr);
void	show_alloc_mem();

/* Alloc Sub-functions */
int	inside_heap(void *ptr);
t_alloc	extend_heap(t_alloc last, size_t size);
t_alloc	get_mdata(void *ptr);
t_alloc	find_block(t_alloc *last, size_t size);
void	split_block(t_alloc block, size_t size);
t_alloc	merge_block(t_alloc block);
void	copy_block(t_alloc src, t_alloc dst);

#endif /* !ALLOC_H_ */
